package com.pantuo.common.utils;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * Page object with jquery DataTable members
 */
public class DataTablePage<T> extends PageImpl<T> {
    private int draw;

    public Object tableInfo;
    public Map<Object, Object> hold = new LinkedHashMap<Object, Object>();

    public DataTablePage(List content, Pageable pageable, long total) {
        super(content, pageable, total);
    }

    public DataTablePage(List content) {
        super(content);
    }

    public DataTablePage(final Page<T> page) {

        super(page.getContent(), page.getPageable(), page.getTotalElements());
        this.draw = draw;
        tableInfo = new A();
    }

    class A {
        public String getAbs() {
            return this.getClass().getName().concat("nihao");
        }
    }

    public DataTablePage<T> putTableInfo(Object key, Object value) {
        hold.put(key, value);
        return this;
    }

    public int getDraw() {
        return draw;
    }

    public void setDraw(int draw) {
        this.draw = draw;
    }

    public long getRecordsTotal() {
        return this.getTotalElements();
    }

    public void setRecordsTotal(long recordsTotal) {
    }

    public long getRecordsFiltered() {
        return this.getTotalElements();
    }

    public void setRecordsFiltered(long recordsFiltered) {
    }

    public Object getTableInfo() {
        return tableInfo;
    }

    public void setTableInfo(Object tableInfo) {
        this.tableInfo = tableInfo;
    }

    public Map<Object, Object> getHold() {
        return hold;
    }

    public void setHold(Map<Object, Object> hold) {
        this.hold = hold;
    }

}
